package com.six.firstpage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Link;
import com.six.core.vo.Result;
import com.six.firstpage.service.LinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 09:38
 * @Description:
 */
@Api(value = "firstpage/link", tags = {"链接管理后端接口"})
@RestController
@RequestMapping("firstpage/link")
public class LinkController {

    @Autowired
    private LinkService linkService;


    @GetMapping("getAllLink")
    public Result getAllLink(){
        List<Link> allLink = linkService.getAllLink();
        return new Result(2000,"查询所有友情链接成功",allLink);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "name", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "status", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getLinkByName/{current}/{pageSize}")
    public Page<Link> getLinkByName(String name, @RequestParam(defaultValue = "0") Integer status, @PathVariable  @RequestParam(defaultValue = "1") Integer current, @PathVariable  @RequestParam(defaultValue = "5") Integer pageSize  ){
        return linkService.getLinkByName(name,status,current,pageSize);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Link", name = "link", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addLink")
    public Integer addLink(@RequestBody Link link){
        return linkService.addLink(link);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Link", name = "link", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateLink")
    public Integer updateLink(@RequestBody Link link){
        return linkService.updateLink(link);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "linkId", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delLink/{linkId}")
    public Integer delLink(@PathVariable Integer linkId){
        return linkService.delLink(linkId);
    }

}
